package com.example.dsonblog.controller;

import com.example.dsonblog.pojo.Article;
import com.example.dsonblog.service.ArticleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class BlogController {

    @Autowired
    private ArticleService articleService;

    @RequestMapping("/index")
    public String index(Model model,@RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum){
        PageHelper.startPage(pageNum,2);
        List<Article> articles = articleService.findArticles();
        PageInfo<Article> pageInfo = new PageInfo<Article>(articles);
        model.addAttribute("pageInfo",pageInfo);
        return "index";
    }


}
